#include "CLayer.h"
#include "SGD Wrappers/CSGD_TextureManager.h"
#include "SGD Wrappers/CSGD_Direct3D.h"
#include "CTileManager.h"
#include "CGame.h"

CLayer::CLayer()
{

}

CLayer::~CLayer()
{

}

void CLayer::Init(/*int nNumTiles*/)
{
	//m_vTiles = ne
}

void CLayer::Shutdown()
{

}

void CLayer::Render()
{
	//RECT temp;
	for(int x = 0; x < CTileManager::GetInstance()->MapWidth(); x++)
		for(int y = 0; y < CTileManager::GetInstance()->MapHeight(); y++)
		{
			RECT tempTwo;
			tempTwo.left = (long)(m_vTiles[x + y * CTileManager::GetInstance()->MapWidth()]->TopX());
			tempTwo.top = (long)(m_vTiles[x + y * CTileManager::GetInstance()->MapWidth()]->TopY());
			tempTwo.right = tempTwo.left + CTileManager::GetInstance()->TileWidth();
			tempTwo.bottom = tempTwo.top + CTileManager::GetInstance()->TileHeight();
			
			if((long)(m_vTiles[x + y * CTileManager::GetInstance()->MapWidth()]->TopX()) == 384 && (long)(m_vTiles[x + y * CTileManager::GetInstance()->MapWidth()]->TopY()) == 800)
			{
				int dfajlksdjf = 32;
				dfajlksdjf++;
			}


			//if(IntersectRect(&temp, &CGame::GetInstance()->RectCamera(), &tempTwo))
			{
				CSGD_TextureManager::GetInstance()->Draw(
					CTileManager::GetInstance()->TileSetImage(),
					y * CTileManager::GetInstance()->TileHeight() - CGame::GetInstance()->RectCamera().left, 
					x * CTileManager::GetInstance()->TileWidth() - CGame::GetInstance()->RectCamera().top,  
					1,1,&m_vTiles[x + y * CTileManager::GetInstance()->MapWidth()]->DrawRect());
			}
			
		}
}

void CLayer::RemoveTile(CTile* pTile) 
{
	vector<CTile*>::iterator StuffIter = m_vTiles.begin();

	while(StuffIter != m_vTiles.end())
	{
		if((*StuffIter)->TopX() == pTile->TopX() && (*StuffIter)->TopY() == pTile->TopY())
		{
			m_vTiles.erase(StuffIter);
			return;
		}
		++StuffIter;
	}
}